package com.rede.didiok.rank.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rede.didiok.common.dto.ContinuousDayDto;
import com.rede.didiok.common.dto.rank.RankMemberDto;
import com.rede.didiok.rank.entity.RankMemberEntity;

/**
 * 榜单成员
 * 
 * @author Rede
 * @email didiok@foxmail.com
 * @date 2023-07-20 22:09:24
 */
@Mapper
public interface RankMemberDao extends BaseMapper<RankMemberEntity> {

    /**
     * 修改指定榜单成员的发布状态
     * @param memberUid
     * @param code
     */
    void updateRankMemberPublishStatus(@Param("memberUid") String memberUid, @Param("code") int code);


    /**
     * 通过榜单 rankUid 获取榜单成员数量
     *
     * @return
     */
    @Select("SELECT rank_uid, COUNT(rank_uid) as count FROM  r_rank_member where status = 1 GROUP BY rank_uid")
    List<Map<String, Object>> getMemberCountByRank();

    /**
     * 获取一年内的文章贡献数
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @Select("SELECT DISTINCT DATE_FORMAT(create_time, '%Y-%m-%d') DATE, COUNT(uid) COUNT FROM r_rank_member WHERE 1=1 && status = 1 && create_time >= #{startTime} && create_time < #{endTime} GROUP BY DATE_FORMAT(create_time, '%Y-%m-%d')")
    List<Map<String, Object>> getRankMemberContributeCount(@Param("startTime") String startTime, @Param("endTime") String endTime);

    /**
     * 通过分类获取博客数量
     *
     * @return
     */
    @Select("SELECT cat_uid, COUNT(cat_uid) AS count FROM  r_rank_member where status = 1 GROUP BY cat_uid")
    List<Map<String, Object>> getRankMemberCountByCategory();


    /**
     * 通过标签获取博客数量
     *
     * @return
     */
    @Select("SELECT grade_uid, COUNT(grade_uid) as count FROM  r_rank_member where status = 1 GROUP BY grade_uid")
    List<Map<String, Object>> getRankMemberCountByMemberGrade();


    /**
     * 根据传参条件 查询page
     *
     * @param page
     * @param rankMemberDto
     * @return
     */
    Page<RankMemberEntity> queryPage(Page<RankMemberEntity> page, @Param("rankMember") RankMemberDto rankMemberDto);


    /**
     * 根据传参条件 查询page
     *
     * @param page
     * @param rankMemberDto
     * @return
     */
    Page<RankMemberEntity> queryPageWithAttrInfo(Page<RankMemberEntity> page, @Param("rankMember") RankMemberDto rankMemberDto);

    /**
     * 通过标签获取博客数量
     *
     * @return
     */
    @Select("SELECT tag_uid, COUNT(tag_uid) as count FROM  t_blog where status = 1 GROUP BY tag_uid")
    List<Map<String, Object>> getBlogCountByTag();

    /**
     * 通过分类获取博客数量
     *
     * @return
     */
    @Select("SELECT blog_sort_uid, COUNT(blog_sort_uid) AS count FROM  t_blog where status = 1 GROUP BY blog_sort_uid")
    List<Map<String, Object>> getBlogCountByBlogSort();

    /**
     * 根据用户列表ID  查询各用户发表博客数
     *
     * @param users
     * @return
     */
    List<Map<String, String>> getUsersRankMemberCountByUserId(@Param("userUids") List<String> userUids);


    /**
     * 获取连续发表博客天数
     *
     * @param userUid
     * @param day
     * @return
     */
    ContinuousDayDto getPublishContinuousDays(@Param("userUid") String userUid, @Param("day") String day);

    /**
     * 修改榜单成员content
     * @param uid
     * @return
     */
    boolean updateContentById(@Param("uid")String uid, @Param("content")String content);

    /**
     * 查询指定状态的榜单成员，包括content
     * @param status
     * @return
     */
    List<RankMemberEntity> listRankMemberWithContent(@Param("status") int status);

    /**
     * 榜单成员下架操作
     * @param uid
     * @param rejectReason
     * @param auditStatus
     * @param isPublish
     * @return
     */
    Boolean revocationRankMember(@Param("uid") String uid, @Param("rejectReason") String rejectReason,
                              @Param("auditStatus") Integer auditStatus, @Param("isPublish") Integer isPublish);

    /**
     * 根据 uid/oid 查询 RankMemberEntity
     * @param uid
     * @param oid
     * @return
     */
    RankMemberEntity getWithAttrInfoById(@Param("uid") String uid, @Param("oid")Integer oid);

    /**
     * 根据 uid/oid 查询 RankMemberEntity
     * @param uid
     * @param oid
     * @return
     */
    RankMemberEntity getRankMemberDetailInfoById(@Param("uid") String uid, @Param("oid")Integer oid);

    /**
     * 根据 条件 查询 RankMemberUid
     *
     * @param rankMemberDto
     * @return
     */
    List<RankMemberDto> listRankMemberUid(@Param("rankMember") RankMemberDto rankMemberDto);
}
